package com.bawei.common.model

import com.bawei.common.api.BaseApiServer
import com.bawei.network.HttpInterceptorType
import com.bawei.network.HttpManager


/**
 * Author: Jason Zhang
 * Date: 2024/6/4
 * Desc:
 */
abstract class BaseRepository<T: BaseApiServer>{

    private var tokenApiServer: T? = null
    private var uploadApiServer: T? = null
    private var signApiServer: T? = null
    private var commonApiServer: T? = null

    fun <T> createApiServer(clazz: Class<*>, type: HttpInterceptorType): T {
        if (type == HttpInterceptorType.TOKEN){
            if (tokenApiServer  == null){
                tokenApiServer = HttpManager.createApi(clazz, type)
            }
            return tokenApiServer as T
        }

        if (type == HttpInterceptorType.SIGN){
            if (signApiServer  == null){
                signApiServer = HttpManager.createApi(clazz, type)
            }
            return signApiServer as T
        }

        if (type == HttpInterceptorType.UPLOAD){
            if (uploadApiServer  == null){
                uploadApiServer = HttpManager.createApi(clazz, type)
            }
            return uploadApiServer as T
        }

        if (type == HttpInterceptorType.INTERFACE){
            if (tokenApiServer  == null){
                commonApiServer = HttpManager.createApi(clazz, type)
            }
            return commonApiServer as T
        }
        return HttpManager.createApi(clazz, type) as T
    }


}